package com.suotuo.module.sys.controller;

import com.suotuo.common.util.Result;

import com.suotuo.module.sys.dto.GameDTO;
import com.suotuo.module.sys.dto.GameListDTO;
import com.suotuo.module.sys.entity.Games;
import com.suotuo.module.sys.service.GameService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liulubingjava@163.com
 * @data 2019/1/18 17:20
 */
@RestController
@RequestMapping("game")
@Log
public class GameController {
    @Autowired
    private GameService gameService;
    @RequestMapping("/list")
    public Result getAllGames(@RequestBody GameListDTO gameDTO){
        Page<Games> gamesPage = gameService.findAll(gameDTO.getPage(),gameDTO.getSize(),gameDTO.getSort(),gameDTO.getPropertie());
        return Result.success(gamesPage.getContent());
    }
    @RequestMapping("/list/category")
    public Result getGamesByCategory(@PathVariable String categoryId,
                                     @RequestParam Integer page,
                                     @RequestParam Integer size){
        Page<Games> gamesPage = gameService.findByCategoryId(categoryId,page,size);
        return Result.success(gamesPage);
    }
    @RequestMapping("/save")
    public Result save(@RequestBody GameDTO gameDTO){
        gameService.save(gameDTO);
        return Result.success("新增游戏成功");
    }
    @RequestMapping("/getgame")
    public Result getGame(@RequestParam String gameId){
        return Result.success(gameService.getGame(gameId));
    }
    @RequestMapping("/update")
    public Result update(@RequestBody GameDTO gameDTO,@RequestParam String gameId){
        gameService.update(gameDTO,gameId);
        return Result.success("修改游戏成功");
    }
    @RequestMapping("/delete/one")
    public Result delete(@RequestParam String gameId){
        gameService.deleteOne(gameId);
        return Result.success("删除单个游戏成功");
    }
    @RequestMapping("/delete/more")
    public Result delete (@RequestParam List<String> list){
        gameService.deleteMore(list);
        return Result.success("删除多个游戏成功");
    }


}
